home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-09-11 | 4.6 KB | 174 lines | [TEXT/CWIE] |
- // RankedQuery.h
- // Copyright: © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
- // Utility for preparing queries for ranked search -- used by both vector & inverted accessors.
- // Not directly used by client code, but rather by accessor implementations.
-
- #pragma once
- #ifndef RankedQuery_h
- #define RankedQuery_h
-
- #pragma import on
-
- #include "RankedAccessor.h"
- #include "Similarity.h"
- #include "Progress.h"
- #include "SkipList.h"
-
- #pragma IA_BEGIN_EXPORTS
-
- //// RankedQuery: a term-indexed skip list of <term, termInfo+, scaleFactor, queryWeight> entries
- struct RQEntry : public IAStruct {
- RQEntry() : infos(NULL), term(NULL), weight(0.0) {}
- IATerm* term; // the term (pointer into the first info)
- TermInfo** infos; // array of TermInfos -- one per index
- float scaleFactor; // for weighting vectors
- float weight; // this term's weight in the query
- };
-
- class TFMap;
- class StringDocText;
-
- class IAQuery : public SkipList { // a skip list of RQEntry's ordered by term
- public:
- IAQuery() : nIndices(0), SkipList(sizeof(RQEntry)) {}
- virtual ~IAQuery();
-
- // All the work is done by Initialize() -- would be ctor, but need return value.
- // Returns true iff the query analysis was aborted.
- virtual bool Initialize();
-
- virtual IADocText* GetQueryText() = 0;
- virtual uint32 GetNumberOfQueryDocs() = 0;
- virtual RankedQueryDoc* GetQueryDocs() = 0;
- void SetIndicies (TermIndex** indicies, uint32 numberofindicies);
- uint32 GetNumberOfIndicies() {return nIndices;}
-
- bool Remove(RQEntry* rqe);
- RQEntry* First() { return (RQEntry*)SkipList::First(); }
- RQEntry* Next(RQEntry* rqe) { return (RQEntry*)SkipList::Next(rqe); }
- virtual bool ComputeTermScaleFactors();
-
- void SetSimilarity (Similarity* similarity) {sim = similarity;}
- void SetProgress (Progress* p) {progress = p;}
- Similarity* GetSimilarity () {return sim;}
- Progress* GetProgress (){return progress;}
-
- protected:
-
- bool LessThanInline(SkipNode n, SkipNode m);
- bool LessThan(const SkipNode n, const SkipNode m);
- bool Equal(const SkipNode n, const SkipNode m);
- virtual SkipNode SetFinger(const SkipNode k, SL_Finger f);
-
- void AddTerms(TFMap* tfMap);
- bool ComputeDocTFMaps(RankedQueryDoc* docQuery, uint32 nDocs, TFMap** tfMaps);
- void WeightTFMap(TFMap* tfMap);
- void SumWeights(TFMap** maps, uint32 nMaps);
- void SetWeight(IATerm* term, float weight);
- private:
- TermIndex** indices;
- uint32 nIndices;
- Similarity* sim;
- Progress* progress;
-
- };
-
- class IARankedQuery : public IAQuery {
- public:
- IARankedQuery(): fTextQuery(NULL), fTextQueryLength(0),
- fDocQuery(NULL), fNumberOfDocs(0), fStringText(NULL){}
- IARankedQuery(byte* textQuery, uint32 textQueryLen,
- RankedQueryDoc* docQuery, uint32 nDocs);
-
- virtual ~IARankedQuery();
-
- void SetTextQuery(byte* textQuery, uint32 textQueryLen);
- void SetQueryDoc(RankedQueryDoc* docQuery, uint32 nDocs);
-
- virtual IADocText* GetQueryText();
- virtual uint32 GetNumberOfQueryDocs();
- virtual RankedQueryDoc* GetQueryDocs();
-
- private:
- byte* fTextQuery;
- uint32 fTextQueryLength;
- RankedQueryDoc* fDocQuery;
- uint32 fNumberOfDocs;
- StringDocText* fStringText;
- };
-
- class IADocTextQuery : public IAQuery {
- public:
- IADocTextQuery () : fTextQueryDoc(NULL), fDocQuery(NULL), fNumberOfDocs(0){}
- IADocTextQuery (IADocText* textQueryDoc,
- RankedQueryDoc* docQuery, uint32 nDocs);
-
- virtual ~IADocTextQuery();
-
- void SetDocTextQuery (IADocText* textQueryDoc);
- void SetQueryDoc (RankedQueryDoc* docQuery, uint32 nDocs);
-
- virtual IADocText* GetQueryText();
- virtual uint32 GetNumberOfQueryDocs();
- virtual RankedQueryDoc* GetQueryDocs();
-
- private:
- IADocText* fTextQueryDoc;
- RankedQueryDoc* fDocQuery;
- uint32 fNumberOfDocs;
- };
-
- inline void IAQuery::SetIndicies (TermIndex** inds, uint32 numberofindicies)
- {
- indices = inds;
- nIndices = numberofindicies;
- }
-
- inline void IARankedQuery::SetQueryDoc (RankedQueryDoc* docQuery, uint32 nDocs)
- {
- fDocQuery = docQuery;
- fNumberOfDocs = nDocs;
- }
-
-
- inline uint32 IARankedQuery::GetNumberOfQueryDocs()
- {
- return fNumberOfDocs;
- }
-
- inline RankedQueryDoc* IARankedQuery::GetQueryDocs()
- {
- return fDocQuery;
- }
-
- inline IADocText* IARankedQuery::GetQueryText()
- {
- return (IADocText*)fStringText;
- }
-
- inline void IADocTextQuery::SetDocTextQuery(IADocText* textQueryDoc)
- {
- fTextQueryDoc = textQueryDoc;
- }
-
- inline void IADocTextQuery::SetQueryDoc (RankedQueryDoc* docQuery, uint32 nDocs)
- {
- fDocQuery = docQuery;
- fNumberOfDocs = nDocs;
- }
-
- inline uint32 IADocTextQuery::GetNumberOfQueryDocs()
- {
- return fNumberOfDocs;
- }
-
- inline RankedQueryDoc* IADocTextQuery::GetQueryDocs()
- {
- return fDocQuery;
- }
-
- #pragma IA_END_EXPORTS
-
- #pragma import reset
- #endif
-